/**
 * 
 */
package com.eunion.web.character.controller;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.eunion.core.DateJsonProcessor;
import com.eunion.core.LogUtil;
import com.eunion.web.character.entity.CharacterClass;
import com.eunion.web.character.service.CharacterClassService;
import com.eunion.web.common.base.BaseService;
import com.eunion.web.common.base.BaseTableCommonController;
import com.eunion.web.common.vo.Web;

import net.sf.json.JsonConfig;

/**
 * 
 * 
 * @author changzuzhe
 */
@Controller
@RequestMapping(value = "/api/characterClass")
public class CharacterClassController extends BaseTableCommonController<CharacterClass, Integer> {
	@Autowired
	private CharacterClassService characterClassService;
	@Autowired
    private ApplicationContext applicationContext;
	
	@Override
	protected BaseService<CharacterClass, Integer> getBaseService() {
		// TODO Auto-generated method stub
		return characterClassService;
	}

	@PostMapping(value = Web.URL_SEP_SAVE)
	public String addCharacterClass(CharacterClass characterClass,BindingResult result, Model model, HttpServletRequest request) {
		characterClass.setSslx("mbti_zyxgcp");
		characterClassService.save(characterClass);
		
		return getUrlBase().concat("-add");
	}
	
	@RequestMapping(value = Web.URL_SEP_UPDATE, method = {RequestMethod.POST})
	public String updateCharacterClass(CharacterClass characterClass,BindingResult result, Model model, HttpServletRequest request) {
		characterClass.setSslx("mbti_zyxgcp");
		characterClassService.saveAndFlush(characterClass);
		model.addAttribute(Web.OBJ, characterClass);
		return getUrlBase().concat("-edit");
	}
	
	/**
	 * 进入性格管理页面
	 * @return
	 */
	@RequestMapping("/index")
	public String index() {
		return getUrlBase();
	}

	@Override
	protected String getUrlBase() {
		return "admin/character/characterclass";
	}
}
